{% extends 'base.html' %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
  <h2 class="page-header">公司列表</h2>
  <a href="{{ url_for('add_company') }}" class="btn btn-primary"><i class="bi bi-plus-lg"></i> 添加公司</a>
</div>
<div class="container mt-5">
  <table class="table table-bordered table-striped">
    <thead class="table-light">
      <tr>
        <th>中文名</th>
        <th>英文名</th>
        <th>中文地址</th>
        <th>英文地址</th>
        <th>网址</th>
        {% if is_admin %}
        <th>操作</th>
        {% endif %}
      </tr>
    </thead>
    <tbody>
      {% for company in companies %}
      <tr>
        <td>{{ company.name_cn }}</td>
        <td>{{ company.name_en }}</td>
        <td>{{ company.address_cn }}</td>
        <td>{{ company.address_en }}</td>
        <td>
          <a href="{{ company.website }}" target="_blank">{{ company.website }}</a>
        </td>
        {% if is_admin %}
        <td>
          <a href="{{ url_for('edit_company', company_id=company.id) }}" class="btn btn-sm btn-info">编辑</a>
          <form action="{{ url_for('delete_company', company_id=company.id) }}" method="POST" style="display: inline;">
            <button type="submit" class="btn btn-sm btn-danger" onclick="return confirm('确定要删除这家公司吗？此操作不可恢复！')">
              删除
            </button>
          </form>
        </td>
        {% endif %}
      </tr>
      {% endfor %}
    </tbody>
  </table>
  <a href="/" class="btn btn-secondary">返回首页</a>
</div>
{% endblock %}